<?php
/**
 * ECSHOP 淘宝登陆返回程序
 * ============================================================================
 * 版权所有 2005-2010 上海商派网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.ecshop.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: liuhui $
 * $Id: payment.php 17063 2010-03-25 06:35:46Z liuhui $
*/

define('IN_ECS', true);

$_SESSION['admin_id'] = $_REQUEST['ECSCP']['admin_id'];

require('includes/init.php');
include_once('../includes/cls_taobao.php');

$top_session = $_REQUEST['session'];
$taobao_name = $_REQUEST['taobao_user_nick'];

$taobao = new taobao($_CFG['certificate_id']);
$taobao->service_valid();

$taobao_account_bind = $taobao->get_nick();
if ($taobao_account_bind['result'] != 'succ' || $taobao_name != $taobao_account_bind['result_msg'])
{
    die('您此次登陆的淘宝账号和网店绑定的账号不同，请重新绑定账号后重试。');
}

$sql = "SELECT session FROM " . $ecs->table('taobao') . " WHERE session = '$top_session'";

$agency_id = $db->getOne($sql);

if (empty($agency_id))
{
    $sql = "TRUNCATE " . $ecs->table('taobao');

    $db->query($sql);

    $minus_stock_sql = "INSERT INTO " . $GLOBALS['ecs']->table('taobao') . "
                    (session,nick) VALUES ('".$top_session."','".$taobao_name."')";

    $GLOBALS['db']->query($minus_stock_sql, 'SILENT');
}
echo "<body onload=\"setTimeout('window.close()',3)\"></body>";
?>